Skip to content

TYP: de-duplicate some type unions #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2022
Merged

Conversation

twoertwein
Copy link
Member

This will avoid the new behavior/regression in mypy 0.981python/mypy#13760

@bashtage
Copy link
Contributor

Lgtm.

@bashtage bashtage merged commit f54d5ed into pandas-dev:main Sep 29, 2022
@twoertwein
Copy link
Member Author

Should have maybe waited for more consensus on the mypy issue, luckily easy to revert :)

@twoertwein
Copy link
Member Author

Might also consider skipping flake8-pyi's check for int | float | complex. Personally, I would like to avoid redundant unions, but they serve also a documentation pupose for which it might be more explicit to keep redundant unions.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Sep 29, 2022

Might also consider skipping flake8-pyi's check for int | float | complex. Personally, I would like to avoid redundant unions, but they serve also a documentation pupose for which it might be more explicit to keep redundant unions.

I'm in favor of the redundancy, because it helps people understand what arguments are possible. Trying to help the novices, not just the experts like us!

@bashtage
Copy link
Contributor

I also prefer redundancy, esp for int | float.

twoertwein added a commit to twoertwein/pandas-stubs that referenced this pull request Sep 29, 2022
@twoertwein
Copy link
Member Author

Opened #342 to revert the change and disable the flake8-pyi check. Also opened a PR for the few pyi files in pandas itself.

@AlexWaygood
Copy link

AlexWaygood commented Sep 29, 2022

(flake8-pyi maintainer here)

In case it's helpful: we deliberately excluded type aliases from Y041 on the grounds that redundant unions often serve valuable documentation purposes. So flake8-pyi will complain about this code:

x: int | float

But it deliberately won't complain about this code:

from typing_extensions import TypeAlias
_IntOrFloat: TypeAlias = int | float
x: _IntOrFloat

As such, you'll still find a few redundant unions in typeshed that have been deliberately left in, e.g. https://github.com/python/typeshed/blob/7576805aee96fe091821d4c963c46645a1894052/stdlib/fractions.pyi#L8

@twoertwein
Copy link
Member Author

But it deliberately won't complain about this code:

I think it did that manually :)

Dr-Irv pushed a commit that referenced this pull request Sep 30, 2022
* Revert "TYP: de-duplicate some type unions (#341)"

This reverts commit f54d5ed.

* disable flake8-pyi's Y041

* int + float

* mypy

* pyright and mypy need ignore comments at different lines

* typing -> type
@twoertwein twoertwein deleted the scalar branch February 10, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants